#include<stdio.h>
#include<stdlib.h>
#define MAXN 10
#define MAX(X,Y)    (X)>(Y)?(X):(Y)
#define MIN(X,Y)    (X)<(Y)?(X):(Y)
int F[MAXN],Dp[MAXN];

int main(){
    int i,j,A[10]={0,-2,5,3,-1,8,5,-4,0,1},N=9,M=3;
    memset(Dp,-1,sizeof(Dp));
    memset(F,-1,sizeof(F));
    Dp[0] = F[0] = 0;
    for(i=1;i<=N;i++)
        for(j=MIN(i,M);j>=1;j--){
            F[j] = MAX(F[j],Dp[j-1]);
            F[j] += A[i];
            Dp[j] = MAX(Dp[j],F[j]);
        }
    printf("%d\n",Dp[M]);
    return 0;
}
